﻿using System;
using System.Collections.Generic;
using System.Text;
using QuanLyKhachSan;
using System.Data.SqlClient;
using System.Data;
using NUnit.Framework;

namespace UnitTest
{
    //[TestFixture]
    //public class clsTestPhong
    //{
    //    public SqlConnection conn;
    //    public SqlDataAdapter adpt;
    //    public SqlCommand cmdSelect_tbl;
    //    public DataTable expectedData;

    //    public PhongDTO phongdto;


    //}
    public class clsTestPhong : clsTest
    {
        private PhongDTO phong;
        [Test]
        public void TestInsert()
        {
            phong = new PhongDTO();
            phong.DanhDau = 0;
            phong.GhiChu = "Test Ins Ghi Chú";
            phong.MaLoaiPhong = 1;
            phong.TenPhong = "Test Ins Tên Phòng";
            phong.TinhTrang = 0;

            bool kq = PhongDAO.Insert(phong);

            Dictionary<string, object> para = new Dictionary<string,object>();
            para.Add("tenPhong", phong.TenPhong);
            para.Add("maLoaiPhong", phong.MaLoaiPhong);
            para.Add("tinhTrang", phong.TinhTrang);
            para.Add("ghiChu", phong.GhiChu);
            para.Add("danhDau", phong.DanhDau);

            expectedData = select_DataTable("Phong", para);
            if (expectedData.Rows.Count == 0)
            {
                Assert.IsFalse(kq);
            }
            else
            {
                Assert.GreaterOrEqual(expectedData.Rows.Count, 1, "Cần Insert xuống CSDL");
                Assert.IsTrue(kq);
            }
        }
        public bool Assert_Clauses(DataTable expected, PhongDTO actual)
        {
            if (expected.Rows.Count > 0)
            {
                DataRow dr = expected.Rows[0];
                Assert.AreEqual((int)dr["maPhong"], actual.MaPhong, "I hope the maPhong is the same");
                Assert.AreEqual(dr["tenPhong"], actual.TenPhong, "TenPhong not the same");
                Assert.AreEqual((int)dr["maLoaiPhong"], actual.MaLoaiPhong, "I hope the maLoaiPhong is the same");
                //Assert.AreEqual(int.Parse(dr["tinhTrang"].ToString()), actual.TinhTrang, "tinhTrang not the same");
                Assert.AreEqual((int)dr["danhDau"], actual.DanhDau, "danhDau not the same");
                Assert.AreEqual(dr["ghiChu"], actual.GhiChu, "ghiChu not the same");
                return true;
            }

            return false;
        }
        [Test]
        public void TestUpdate()
        {
            phong = new PhongDTO();
            phong.DanhDau = 0;
            phong.GhiChu = "test ghi chú";
            phong.MaPhong = 1;
            phong.TenPhong = "Test Tên Phòng";
           // phong.TinhTrang = 0;
            phong.MaLoaiPhong = 1;

            bool kq  = PhongDAO.Update(phong);
            Dictionary<string, object> para = new Dictionary<string, object>();
            para.Add("maPhong", phong.MaPhong);

            expectedData = select_DataTable("Phong", para);
            if (expectedData.Rows.Count == 0)
            {
                Assert.IsFalse(kq);
            }
            else
            {
                Assert_Clauses(expectedData, phong);
                Assert.IsTrue(kq);
            }
        }
    }
}
